package de.tudarmstadt.fgbs.cafe.exception;

import de.tudarmstadt.fgbs.cafe.structure.enumeration.Subsystem.Subystem;

/**
 * The class {@link FlawedConfigurationException} is a {@link Exception} that is
 * thrown when a configuration is flawed.
 * 
 * @author Christian Schlehuber
 * @version 0.4
 * @since 0.1
 * 
 */
public class FlawedConfigurationException extends Exception {

    /**
     * The unique id which is used for serialization.
     */
    private static final long serialVersionUID = -6656152738749525171L;

    /**
     * The subsystem the exception occurs in.
     */
    private Subystem subsystem;

    /**
     * Constructs a new {@link FlawedConfigurationException} with the specified
     * detail message and the subsystem.
     * 
     * @param message
     *            The detail message.
     * @param subsystem
     *            The name of the subsystem, the exception occurs in.
     */
    public FlawedConfigurationException(String message, Subystem subsystem) {
	super(message);
	this.subsystem = subsystem;
    }

    /**
     * Constructs a new {@link FlawedConfigurationException} with the specified
     * detail message, subsystem and cause.
     * 
     * @param message
     *            The detail message.
     * @param subsystem
     *            The name of the subsystem, the exception occurs in.
     * @param cause
     *            The cause of this exception.
     */
    public FlawedConfigurationException(String message, Subystem subsystem,
	    Throwable cause) {
	super(message, cause);
	this.subsystem = subsystem;
    }

    /**
     * Constructs a new exception with the subsystem and the specified cause.
     * The detail message is set to the <code>cause.{@link #toString()}</code>
     * or <code>null</code> if the cause is <code>null</code>.
     * 
     * @param subsystem
     *            The name of the subsystem, the exception occurs in.
     * @param cause
     *            The cause of this exception.
     */
    public FlawedConfigurationException(Subystem subsystem, Throwable cause) {
	super(cause);
	this.subsystem = subsystem;
    }

    /**
     * Gets the name of the subsystem the exception occurs in.
     * 
     * @return The name of the subsystem, the exception occurs in.
     */
    public String getSubsystem() {
	return subsystem.name();
    }
}
